package com.qf.web;

import com.qf.domain.Student;
import com.qf.service.ServiceMap;
import com.qf.service.impl.ServiceMapImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

@WebServlet("/map")
public class Map extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            req.setCharacterEncoding("utf-8");
            java.util.Map<String, String[]> parameterMap = req.getParameterMap();
            Student student=new Student();
            BeanUtils.populate(student,parameterMap);
            ServiceMap serviceMap=new ServiceMapImpl();
            int i = serviceMap.mapA(student);
            if (i>0){

                resp.sendRedirect(req.getContextPath()+"/result");
            }else {
                req.setAttribute("msg","shifdgrg");
                req.getRequestDispatcher("/msg.jsp").forward(req,resp);
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
           e.printStackTrace();
        }

    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
